# coding:utf-8


from snownlp import sentiment, SnowNLP

# sentiment.train('neg.txt','pos.txt')

def train_data():
    sentiment.train('data/train/neg.txt', 'data/train/pos.txt')
    sentiment.save('model/sentiment.marshal')


def predict():
    with open('data/test/pos.txt','r', encoding='utf-8') as file:
        lines = [line[2:] for line in file.readlines()]
        for line in lines[:20]:
            print(line, '->实际：积极，测试：',SnowNLP(line).sentiments)
    with open('data/test/neg.txt','r', encoding='utf-8') as file:
        lines = [line[2:] for line in file.readlines()]
        for line in lines[:20]:
            print(line, '->实际：消极，测试：',SnowNLP(line).sentiments)

if __name__ == '__main__':
    predict()
    # train_data()
    # lines = [line for line in open('data/train/pos.txt', 'r', encoding='utf-8').readlines()]
    # print(lines[:10])